package books;

/**
 * 定义Bool 书的一个类的类型
 */
public class Book {

    private String name;      // 书名
    private String author;    // 书的作者
    private double price;     // 书的价格
    private String type;      // 书的类型
    private boolean isBorrowed;  // 书的借出状态


    public Book(String name, String author, double price, String type) {   // 构造方法
        this.name = name;
        this.author = author;
        this.price = price;
        this.type = type;

        // isBoorrowed 不用重新定义，默认是 false 未借出状态，
    }



    /*
    根据 isBoorrwed 类型的布尔值，修改对应的书的出借状态
     */
    private String lendState() {
        String state = "未借出";

        if(this.isBorrowed) {
            state = "已借出";
        }

        return state;
    }



    @Override  // 注解：重写toString()方法，未打印 book 类类型做准备
    public String toString() {
        String condition = this.lendState();

        return "Book{" +
                "书名: '" + name + '\'' +
                ", 作者: '" + author + '\'' +
                ", 价格: " + price +
                "元, 类型: '" + type + '\'' +
                ", 书籍状态: " + condition +
                '}';
    }



    /**
     * 对该类成员的封装
     * 下面是对该类中的类成员的 set 和 get 方法
     * @return
     */
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public boolean isBorrowed() {
        return isBorrowed;
    }

    public void setBorrowed(boolean borrowed) {
        isBorrowed = borrowed;
    }
}
